<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../common/taglibs.jsp" %>

<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<%@ include file="../common/btcss.jsp" %>
	
	<link rel="stylesheet" href="${ctx }/static/lib/weekdatepicker/css/default.css">
	<link rel="stylesheet" href="${ctx }/static/lib/datatables/1.10.9/css/jquery.dataTables.min.css">
	
	<title>资源白名单配置管理系统</title>
</head>
<body>
	<ol class="breadcrumb">
        <li><a href="${ctx }/config/welcome">首页</a></li>
        <li><a href="${ctx }/ipcclist">IPCC设置管理</a></li>
        <li><a href="javascript:void(0);" onclick="javascript:goroutelist()" >航线投放时间段管理</a></li>
        <li><a href="javascript:void(0);" style="text-decoration: none;font-color:gray;">批量修改</a></li>
    </ol>
	<form id="routeform">
		<div class="container-fluid">
		  	<table class="table table-bordered">
		  		<tr>
		  			<td>
						渠道：
	        		</td>
	        		<td>
	        			<%=session.getAttribute("cid") %>
	        		</td>
	        	</tr>
	        	<tr>
	        		<td>
						资源：
	        		</td>
	        		<td>
	        			<%=session.getAttribute("ds") %>
	        		</td>
	        	</tr>
	        	<tr>
	        		<td>
						IPCC：
	        		</td>
	        		<td>
	        			<%=session.getAttribute("ipcc") %>
	        		</td>
		  		</tr>
		  		<tr>
	        		<td>
						投放时间段选择：
	        		</td>
	        		<td>
	        			您选中了<%=request.getAttribute("idNum")%>条航线信息，此<%=request.getAttribute("idNum")%>条航线信息将会被批量修改！<br>
	        			<div id="datepicker" class="col-md-10"></div>
	        		</td>
		  		</tr>
		  		<tr>
	        		<td>
						开启/关闭：
	        		</td>
	        		<td>
	        				<input type="radio" id="status" name="status" value="1" checked/>开启 &nbsp;&nbsp;&nbsp;
	        				<input type="radio" id="status" name="status" value="0"/>关闭
	        		</td>
		  		</tr>
		  	</table>
		</div>
	    
	    <div class="container">
	    	<button id="cancel" type="button" class="btn btn-warning">取消</button>
	    	<button id="submit" type="button" class="btn btn-success">提交</button>
	    </div>
	    
	     <input type="hidden" id="time" name="time"  value=""/>
	     <input type="hidden" id="idNum" name="idNum"  value="<%=request.getAttribute("idNum")%>"/>
	    <input type="hidden" id="idList" name="idList"  value="<%=request.getAttribute("idList")%>"/>
    </form>
	
	<%@ include file="../common/btjs.jsp" %>
	
	<script src="${ctx }/static/lib/weekdatepicker/js/weekDataPicker.js"></script>
	<script src="${ctx }/static/lib/datatables/1.10.9/js/jquery.dataTables.js"></script>
	<script src="${ctx }/static/lib/datatables/1.10.9/js/dataTables.bootstrap.js"></script>
	
	<script type="text/javascript">
		var global;
		
		$(function(){
			global = $("#datepicker").weekDataPicker({
                chooseColor: 'greenyellow',
                chooseRgb: 'rgb(173, 255, 47)',
                unChooseColor: '#eee',
                mode: 'edit',
                data : JSON.parse( '<%=request.getAttribute("time")%>')
            });
            
             $('#submit').click(function(){
	         	var map = global.getData();
	            var s = JSON.stringify(map);
	            $('#time').val(s);
	            if($('#idList').val() == "null"){
	            	allhupdateroute();
	            } else {
					beathupdateroute();
	            }
			});
			
			 $('#cancel').click(function(){
				$('#message').html("");
				window.location.href = 'routelist';
			});
		});
		
		function beathupdateroute() {
			$.ajax({
                cache: true,
                type: "POST",
                url: "beathupdatetroute.ajax",
                data:$('#routeform').serialize(),// 你的formid
                async: false,
                error: function(request) {
                    alert("Connection error");
                },
                success: function(data) {
                    var retJSON = JSON.parse(data);
                    if(retJSON.updatenum > 0) {
                    	window.location.href = 'routelist';
                    } else {
                    	$('#message').html("更新航线失败.");
                    }
                }
            });
		}
		
		function allhupdateroute() {
			$.ajax({
                cache: true,
                type: "POST",
                url: "allupdatetroute.ajax",
                data:$('#routeform').serialize(),// 你的formid
                async: false,
                error: function(request) {
                    alert("Connection error");
                },
                success: function(data) {
                    var retJSON = JSON.parse(data);
                    if(retJSON.updatenum > 0) {
                    	window.location.href = 'routelist';
                    } else {
                    	$('#message').html("更新航线失败.");
                    }
                }
            });
		}
		
		function goroutelist(){
			window.location.href = 'routelist' ;
		};
	</script>
</body>
</html>